package com.becca.cake.core.excel.excelWriter;

import java.lang.reflect.Method;
import java.text.DecimalFormat;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.util.ReflectionUtils;

import com.becca.cake.util.StringUtil;

/**
 * Excel工具类
 * @author hejinguo
 * @version $Id: ExcelUtils.java, v 0.1 2014-4-23 下午09:51:19
 */
public class ExcelWriteUtils {
    private static Log      logger         = LogFactory.getLog(ExcelWriteUtils.class);
    public static final int pointSizeOne   = 18;                                      //excel中字体的大小
    public static final int pointSizetwo   = 12;
    public static final int pointSizeThree = 11;

    /**
     * 金额类型转换
     * @param money
     * @return
     */
    public static String strToDouble(Object money) {
        String moneyFormat = "";
        if (money != null) {
            DecimalFormat bigLoanAmount = new DecimalFormat("#####0.00");
            moneyFormat = bigLoanAmount.format(money);
        } else {
            moneyFormat = "0.00";
        }
        return moneyFormat;
    }

    /**
     * @Title getParameter
     * 通过反射机制获取字段的值
     * @param obj
     * @param attr
     * @param 设定文件
     * @return String 返回类型 
     * @throws
     */
    public static Object getParameter(Object obj, String attr) {
        Object valuObj = null;
        if (StringUtil.isNotEmpty(attr)) {
            Class<? extends Object> clazz = obj.getClass();
            String methodName = "get" + attr.substring(0, 1).toUpperCase() + attr.substring(1);
            Method method = null;
            try {
                method = clazz.getMethod(methodName);
                valuObj = ReflectionUtils.invokeMethod(method, obj);
            } catch (SecurityException e) {
                if (logger.isErrorEnabled()) {
                    logger.error("通过反射机制获取字段的值时安全异常!", e);
                }
            } catch (NoSuchMethodException e) {
                if (logger.isErrorEnabled()) {
                    logger.error("通过反射机制获取字段的值时没有发现该方法异常!", e);
                }
            }
        }
        return valuObj;
    }

}
